<?php
/**
 * @version             $Id: tidyjoomla.php revision date lasteditedby $
 * @package             Joomla
 * @subpackage  Content
 * @copyright   Copyright (C) 2011 - Edosoft Factory. All rights reserved.
 * @license             GNU/GPLv2, see LICENSE.php
 * See COPYRIGHT.php for copyright notices and details.
 */
 // no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.plugin.plugin' );
class plgContentTidyJoomla extends JPlugin {
/**
 * Constructor
 *
 * For php4 compatability we must not use the __constructor as a constructor for plugins
 * because func_get_args ( void ) returns a copy of all passed arguments NOT references.
 * This causes problems with cross-referencing necessary for the observer design pattern.
 *
 * @param object $subject The object to observe
 * @param object $params  The object that holds the plugin parameters
 * @since 1.5
 */
        function plgContentTidyJoomla( &$subject, $params )
        {
                parent::__construct( $subject, $params );
        }

		function onPrepareContent( &$row, &$params, $limitstart )
        {
                global $mainframe;
                //add your plugin codes here
                //no return value
                if (isset($row->text) && $row->text) {
                        if (function_exists('tidy_parse_string')) {
                
                		// Specify configuration
                		$config = array(
                                   'indent'         => true,
                                   'output-xhtml'   => true,
                                   'wrap'           => 200);
                		// get Joomla content encoding
                		$iso = split( '=', _ISO );
                		$encoding = '';
                		$jos_enc = str_replace('-', '', $iso[1]);
                		if (in_array($jos_enc, array('ascii', 'latin0', 'latin1', 'raw', 'utf8', 'iso2022', 'mac', 'win1252', 'ibm858', 'utf16', 'utf16le', 'utf16be', 'big5', 'shiftjis'))) {
                        		$encoding = $jos_enc;
               			 }
                
                		// Tidy
                		$row->text = tidy_repair_string($row->text, $config, $encoding) . "\r\n<!-- cleaned with tidyjoomla, http://www.edosoftfactory.com -->";
                		
       		} 
        	else 
        	{
                $row->text = $row->text ."\r\n<!-- tidy is not available, http://www.edosoftfactory.com -->";
        	}
             
            }           
            
        }


}

 